import Vue from 'vue';
import Vuex from "vuex";
import station from "./store/modules/station"
Vue.use(Vuex);
export default ()=> {
  let store = new Vuex.Store({
    state: {
      name: 'jw'
    },
    mutations: {
      changeName(state,data) {
        state.name = data
      }
    },
    actions: {
      async changeName({commit}, data) {
        await new Promise((resolve,reject)=> {
          setTimeout(()=> {
            commit('changeName',data);
            resolve();
          },2000)
        })
      }
    },
    modules: {
      station
    }
  })
  // 前端运行时 会执行此方法 用服务端的状态替换掉前端的状态
  if(typeof window!=='undefined' && window.__INITIAL_STATE__){
    store.replaceState(window.__INITIAL_STATE__)
  }
  return store;
}